<%--
  Author: DawnFz.com
  Date: 2022/9/14 21:01
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${ctxPath}/static/layui/css/layui.css"/>
    <title>申请报销</title>
    <script src="${ctxPath}/static/layui/layui.js"></script>
    <script src="${ctxPath}/static/js/jquery-3.6.1.min.js"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title"
          style="margin-top: 20px;">
    <legend>申请报销页</legend>
</fieldset>

<form id="userForm" class="layui-form" action="" method="POST">

    <input id="initiator" type="hidden" value="${user.id}"/><br/>


    <div class="layui-form-item" style="margin-left:20px;">
        <div class="layui-inline">
            <label class="layui-form-label">
                标题
            </label>
            <div class="layui-input-block" style="width:190px;">
                <input type="text" id="title"
                       name="title" autocomplete="off"
                       placeholder="请输入标题"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="margin-left:20px;">
        <div class="layui-inline">
            <label class="layui-form-label">
                报销金额
            </label>
            <div class="layui-input-block" style="width:190px;">
                <input type="text" id="price"
                       name="price" autocomplete="off"
                       placeholder="请输入报销金额"
                       class="layui-input">
            </div>
        </div>
    </div>

    <div class="layui-form-item" style="margin-left:20px;">
        <div class="layui-inline">
            <label class="layui-form-label">
                报销原因
            </label>
            <div class="layui-input-block" style="width:190px;">
                <input type="text" id="reason"
                       name="reason" autocomplete="off"
                       placeholder="请输入报销原因"
                       class="layui-input">
            </div>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn"
                    onclick="submitReim();">提交报销
            </button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    layui.use(
        ['form', 'layedit', 'laydate'],
        function () {
            var form = layui.form;
            var layer = layui.layer;
        }
    );

    function reloadPage() {
        window.location = "${ctxPath}/Reim/myInitiate";
    }

    function submitReim() {
        $.ajax(
            {
                url: '${ctxPath}/Reim/submitReim',
                type: 'post',
                data: {
                    initiator: $('#initiator').val(),
                    startDate: $('#startDate').val(),
                    price: $('#price').val(),
                    title: $('#title').val(),
                    reason: $('#reason').val()
                },
                dataType: "json",
                success: function (json) {
                    console.log(json);
                    let ret = json['result'];
                    let cause = json['cause'];
                    if (ret === 'success') {
                        layer.msg('申请报销成功。');
                        setTimeout(reloadPage, 2000);
                    } else {
                        layer.msg('申请报销失败, 原因:' + cause);
                    }
                }
            }
        );
    }

</script>
</body>
</html>


